package com.suxin.socket.yinfei.handler.chain;

import com.alibaba.fastjson.JSON;
import com.suxin.socket.yinfei.AbstractWebSocketConnection;
import com.suxin.socket.yinfei.session.SessionConnectionHolder;

/**
 * @author Tang
 * @classname FinalChainMessageHandler
 * @description [ 推给页面的chain ]
 * @date 2021/8/19 23:20
 */
public class FinalChainMessageHandler extends AbstractChainMessageHandler{

    private SessionConnectionHolder sessionConnectionHolder;

    public FinalChainMessageHandler(SessionConnectionHolder sessionConnectionHolder,
                                    AbstractChainMessageHandler chainMessageHandler) {
        super(chainMessageHandler);
        this.sessionConnectionHolder = sessionConnectionHolder;
    }

    @Override
    protected Object doChainHandler(Object msg) {
        sessionConnectionHolder.getSession().forEach(session -> {
            AbstractWebSocketConnection.sendMsg(JSON.toJSONString(msg),session);
        });
        return msg;
    }
}